package jwdt.xadmin.bbs.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.bbs.bean.TBclass;
import jwdt.xadmin.bbs.service.ClassManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/bbs")
public class ClassManageAction extends BaseAction {

	protected String url = "/xadmin/bbs/";
	private ClassManageService classManageService = (ClassManageService)app.getBean("classManageService");
	
	@RequestMapping("/listClass")
	public Page doList(Form f, Module m) throws Exception {
		//
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TBclass tc = (TBclass)f.copy2Class(TBclass.class);
		return m.getWritePage(f,classManageService.doList(pu,tc).toJson());	
	}

	
	@RequestMapping("/saveClass")
	public Page doSave(Form f, Module m) throws Exception {
		//
		int id = f.getInt("id",0);
		TBclass obj = (TBclass)f.copy2Class(TBclass.class);
		return m.getWritePage(f, classManageService.doSave(obj, id));
	}
	
	@RequestMapping("/loadClass")
	public Page doLoad(Form f, Module m) throws Exception {
		//
		int id = f.getInt("id",0);
		return m.getJsonPage(f, classManageService.doLoad(id));
	}
	
	
	@RequestMapping("/delClass")
	public Page doDel(Form f, Module m) throws Exception {
		//
		int id = f.getInt("id");
		return m.getWritePage(f, classManageService.doDel(id));
	}
	
	@RequestMapping("/updateState")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, classManageService.doUpdateState(id, "zt="+result));
	}
	
	@RequestMapping("/listClassForTree")
	public Page doListForTree(Form f, Module m) throws Exception {
    	return m.getWritePage(f, classManageService.doListForTree());
	}
	
	@RequestMapping("/listClassForCombox")
	public Page doListForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select id, name from bbs_class where zt=1 ORDER BY orders", CacheUtil.C0));
	}
	
	@RequestMapping("/classWindow")
	public Page doLoadWindow(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", classManageService.doLoad(id));
		return m.findPage("/xadmin/bbs/classWindow");
	}
}
